package com.mzy.xmyx.sys.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mzy.xmyx.common.result.Result;
import com.mzy.xmyx.model.sys.RegionWare;
import com.mzy.xmyx.sys.service.RegionWareService;
import com.mzy.xmyx.vo.sys.RegionWareQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 城市仓库关联表 前端控制器
 * </p>
 *
 * @author mzy
 * @since 2023-11-29
 */
@Api(tags = "区域仓库管理")
@RestController
@RequestMapping("/admin/sys/regionWare")
@CrossOrigin
public class RegionWareController {
    @Autowired
    private RegionWareService regionWareService;

    @ApiOperation("获取开通区域列表")
    @GetMapping("/{page}/{limit}")
    public Result list(@PathVariable Integer page,
                       @PathVariable Integer limit,
                       RegionWareQueryVo regionWareQueryVo) {

        IPage<RegionWare> pageModel = regionWareService.selectPage(page, limit, regionWareQueryVo);
        return Result.ok(pageModel);
    }

    @ApiOperation("根据id查询指定区域仓库")
    @GetMapping("/get/{id}")
    public Result getById(@PathVariable Long id) {
        RegionWare regionWare = regionWareService.getById(id);
        return Result.ok(regionWare);
    }


    @ApiOperation("添加区域仓库")
    @PostMapping("/save")
    public Result save(@RequestBody RegionWare regionWare) {
        Boolean isSuccess = regionWareService.saveRegionWare(regionWare);
        return Result.ok(isSuccess);
    }

    @ApiOperation("更新区域仓库状态")
    @PostMapping("/updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable Long id,
                               @PathVariable Integer status) {
        Boolean isSuccess = regionWareService.updateStatus(id, status);
        return Result.ok(isSuccess);
    }

    @ApiOperation("根据id删除区域仓库")
    @DeleteMapping("/remove/{id}")
    public Result updateStatus(@PathVariable Long id) {
        Boolean isSuccess = regionWareService.removeById(id);
        return Result.ok(isSuccess);
    }

    @ApiOperation("批量删除区域仓库")
    @DeleteMapping("/batchRemove")
    public Result updateStatus(@RequestBody List<Long> idList) {
        Boolean isSuccess = regionWareService.batchRemove(idList);
        return Result.ok(isSuccess);
    }
}

